#ifndef _CANARY2_CORO_SLEEP_THIS_CORO_H_
#define _CANARY2_CORO_SLEEP_THIS_CORO_H_

#include <chrono>
#include "sleeping_suspend_manager.h"

namespace wilson::coro
{
    template<typename Schr>
    class sleep_dura_aw
    {
    public:
        sleep_dura_aw(::std::chrono::milliseconds timeout, 
                 sleeping_suspend_manager<Schr>& ssm)
            : sa_timeout{ timeout }, sa_suspend_manager{ ssm }
        {
        }

        bool await_ready() const
        {
            return sa_timeout.count() <= 1;
        }

        void await_suspend(::std::coroutine_handle<> h)
        {
            sa_suspend_manager.add_task(h, sa_timeout);
        }

        constexpr void await_resume() const noexcept {}

    private:
        ::std::chrono::milliseconds sa_timeout;
        sleeping_suspend_manager<Schr>& sa_suspend_manager;
    };

    template<typename Schr, typename Clock>
    class sleep_timep_aw
    {
    public:
        sleep_timep_aw(::std::chrono::time_point<Clock> timeout, 
                       sleeping_suspend_manager<Schr>& ssm)
            : sa_timeout_tp{ timeout }, sa_suspend_manager{ ssm }
        {
        }

        bool await_ready() const
        {
            return sa_timeout_tp.count() <= 1;
        }

        void await_suspend(::std::coroutine_handle<> h)
        {
            sa_suspend_manager.add_task(h, sa_timeout_tp);
        }

        constexpr void await_resume() const noexcept {}

    private:
        ::std::chrono::time_point<Clock> sa_timeout_tp;
        sleeping_suspend_manager<Schr>& sa_suspend_manager;
    };
}

#endif
